<?php
/**
 * Created by PhpStorm.
 * User: deng
 * Date: 2015/3/14
 * Time: 21:19
 */

namespace Test\Controller;

use Common\Controller\NormalApiController;

class InitUserController extends NormalApiController
{
    public function index()
    {
        $username = $_REQUEST['username'];
        $password = $_REQUEST['password'];
        //  print_r($this->_db);
        if (!$username || !$password)
            ClientError('wrong', 400);
        $model = $this->_db->users;
        $data = [
            'auth' => [
                'username' => $username,
                'password' => md5($password)
            ],
            'role' => '0'
        ];
        Success(200, $model->create($data));
    }

    public function verifyUser()
    {
        $userId = $_POST['userId'];
        $model = $this->_db->users;
        Success(200, $model->role->update($userId, '2'));
    }
}